<?php
/**
 * 基础控制器.
 * User: paul
 * Date: 2017/8/20 0020
 * Time: 16:26
 */

namespace api\modules\v1\controllers;

use Yii;
use yii\rest\ActiveController;
use yii\filters\auth\QueryParamAuth;

class BaseController extends ActiveController
{
    //直接在响应主体内包含分页信息
    public $serializer = [
        'class' => 'yii\rest\Serializer',
        'collectionEnvelope' => 'items',
    ];

    public function behaviors() {
        $behaviors = parent::behaviors();

        $currentUrl = Yii::$app->controller->id . '/' . Yii::$app->controller->action->id;
        $accessToken = Yii::$app->request->get('access_token');

        if(1 == 2){
            //验证方法
            $behaviors['authenticator'] = [
                'class' => QueryParamAuth::className(),
                'tokenParam' => 'access_token'
            ];
        }

        return $behaviors;
    }

}